package com.ziyun.erp.modules.supp.utils;

import com.alibaba.fastjson.JSONObject;
import com.ziyun.erp.common.utils.HttpClientUtil;
import com.ziyun.erp.common.utils.JsonUtils;
import com.ziyun.erp.modules.supp.vo.CompanySearchApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

/**
 * 企业查询
 *
 * @author gaosheng
 * @date 2018-09-27 10:49
 */
public class CompanyCheckUtils {

    private static Logger logger = LoggerFactory.getLogger(CompanyCheckUtils.class);

    public static JSONObject companyCheck(String companyName) {
        logger.info("===================company search server start==========================");
        logger.info("===================companyName：" + companyName);
        try {
            StringBuffer sb = new StringBuffer("http://i.yjapi.com/ECIV4/Search");
            sb.append("?key=e9a0a636212b41bba3d19d222a075edb");
            sb.append("&keyword=");
            sb.append(URLEncoder.encode(companyName, "UTF-8"));
            sb.append("&pageSize=20");
            logger.info("===================search server params：" + sb.toString());
            String result = HttpClientUtil.doGet(sb.toString());
            logger.info("===================search server result：" + result);
            JSONObject jsonObjectRs = JSONObject.parseObject(result);
            logger.info("===================company search server end==========================");
            return jsonObjectRs;
        } catch (UnsupportedEncodingException e) {
            logger.info("===================search server error：" + e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
//        companyCheck("北京市海淀区中关村街道李燕复印部");

        String result = "[{\"KeyNo\":\"089663a5fa3e5c9004d86d078e99c127\",\"StartDate\":\"2001-10-23 00:00:00\",\"Status\":\"存续（在营、开业、在册）\",\"No\":\"420103000111638\",\"CreditCode\":\"91420103731072753X\",\"OperName\":\"尚建华\",\"Name\":\"中浩紫云科技股份有限公司\"},{\"KeyNo\":\"300558a9d0331d94b37cbd97397b818e\",\"StartDate\":\"2015-11-26 00:00:00\",\"Status\":\"存续（在营、开业、在册）\",\"No\":\"440301114462007\",\"CreditCode\":\"91440300354477594Q\",\"OperName\":\"姚荣荣\",\"Name\":\"中浩紫云(深圳)科技有限公司\"},{\"KeyNo\":\"cbac2b45492a3c9cea5786375ddb3007\",\"StartDate\":\"2017-11-02 00:00:00\",\"Status\":\"存续（在营、开业、在册）\",\"No\":\"421182000131050\",\"CreditCode\":\"91421182MA491TN70U\",\"OperName\":\"姚荣荣\",\"Name\":\"中浩紫云(武穴)网络科技有限公司\"},{\"KeyNo\":\"321048977375d6e38de03d9deba44915\",\"StartDate\":\"2017-12-05 00:00:00\",\"Status\":\"在营（开业）企业\",\"No\":\"370213230325319\",\"CreditCode\":\"91370213MA3EYPUT7U\",\"OperName\":\"张静\",\"Name\":\"中浩紫云(青岛)网络科技有限公司\"},{\"KeyNo\":\"03ccb2fd76fcfabba961f35431f43c4b\",\"StartDate\":\"2016-04-27 00:00:00\",\"Status\":\"存续（在营、开业、在册）\",\"No\":\"420103000331135\",\"CreditCode\":\"91420103MA4KMGC10F\",\"OperName\":\"侯峰\",\"Name\":\"中浩紫云科技股份有限公司汉口分公司\"}]";
        List<CompanySearchApiResult> objects = (List<CompanySearchApiResult>) JsonUtils.queryJsonToList(result, CompanySearchApiResult.class);
        System.out.println(objects);

    }

}
